
package ch.hearc.coursJava.moo.heritage.entrainement;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Dessin implements Iterable<Formes>
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public Dessin(List<Formes> listFormes)
		{
		this.listFormes = listFormes;
		}

	public Dessin()
		{
		this(new ArrayList<Formes>());
		}

	public Dessin(Dessin source)
		{
		this(source.listFormes);//copie de la structure
		for(Formes formes:source.listFormes)//copie profonde
			{
			source.listFormes.add(formes.cloneOf());
			}
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	@Override
	public String toString()
		{
		StringBuilder builder = new StringBuilder();
		builder.append("Dessin [listFormes=");
		builder.append(this.listFormes);
		builder.append(" Somme aire = " + sommeAire());
		builder.append(" Somme perimetre = " + sommePerimetre());
		builder.append("]");
		return builder.toString();
		}

	@Override
	public Iterator<Formes> iterator()
		{
		return listFormes.iterator();
		}

	public double sommeAire()
		{
		double sum = 0;
		for(Formes forme:listFormes)
			{
			sum += forme.aire();
			}
		return sum;
		}

	public double sommePerimetre()
		{
		double sum = 0;
		for(Formes forme:listFormes)
			{
			sum += forme.perimetre();
			}
		return sum;
		}

	public void add(Formes formes)
		{
		listFormes.add(formes);
		}

	public void remove(Formes formes)
		{
		listFormes.remove(formes);
		}

	public void afficher()
		{
		//TODO
		}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	private List<Formes> listFormes;

	}
